package androidx.appcompat.widget;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import androidx.appcompat.view.menu.g;
import androidx.appcompat.view.menu.m;
import androidx.appcompat.widget.Toolbar;
import b.a.e;
import b.a.f;
import b.a.h;
import b.a.j;
import b.f.l.s;
import b.f.l.w;
import b.f.l.y;

public class x0 implements d0 {

    /* renamed from: a  reason: collision with root package name */
    Toolbar f455a;

    /* renamed from: b  reason: collision with root package name */
    private int f456b;

    /* renamed from: c  reason: collision with root package name */
    private View f457c;

    /* renamed from: d  reason: collision with root package name */
    private View f458d;
    private Drawable e;
    private Drawable f;
    private Drawable g;
    private boolean h;
    CharSequence i;
    private CharSequence j;
    private CharSequence k;
    Window.Callback l;
    boolean m;
    private c n;
    private int o;
    private int p;
    private Drawable q;

    class a implements View.OnClickListener {

        /* renamed from: b  reason: collision with root package name */
        final androidx.appcompat.view.menu.a f459b = new androidx.appcompat.view.menu.a(x0.this.f455a.getContext(), 0, 16908332, 0, 0, x0.this.i);

        a() {
        }

        public void onClick(View view) {
            x0 x0Var = x0.this;
            Window.Callback callback = x0Var.l;
            if (callback != null && x0Var.m) {
                callback.onMenuItemSelected(0, this.f459b);
            }
        }
    }

    class b extends y {

        /* renamed from: a  reason: collision with root package name */
        private boolean f461a = false;

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ int f462b;

        b(int i) {
            this.f462b = i;
        }

        public void a(View view) {
            if (!this.f461a) {
                x0.this.f455a.setVisibility(this.f462b);
            }
        }

        public void b(View view) {
            x0.this.f455a.setVisibility(0);
        }

        public void c(View view) {
            this.f461a = true;
        }
    }

    public x0(Toolbar toolbar, boolean z) {
        this(toolbar, z, h.abc_action_bar_up_description, e.abc_ic_ab_back_material);
    }

    public x0(Toolbar toolbar, boolean z, int i2, int i3) {
        Drawable drawable;
        this.o = 0;
        this.p = 0;
        this.f455a = toolbar;
        this.i = toolbar.getTitle();
        this.j = toolbar.getSubtitle();
        this.h = this.i != null;
        this.g = toolbar.getNavigationIcon();
        w0 u = w0.u(toolbar.getContext(), (AttributeSet) null, j.ActionBar, b.a.a.actionBarStyle, 0);
        this.q = u.g(j.ActionBar_homeAsUpIndicator);
        if (z) {
            CharSequence p2 = u.p(j.ActionBar_title);
            if (!TextUtils.isEmpty(p2)) {
                E(p2);
            }
            CharSequence p3 = u.p(j.ActionBar_subtitle);
            if (!TextUtils.isEmpty(p3)) {
                D(p3);
            }
            Drawable g2 = u.g(j.ActionBar_logo);
            if (g2 != null) {
                z(g2);
            }
            Drawable g3 = u.g(j.ActionBar_icon);
            if (g3 != null) {
                setIcon(g3);
            }
            if (this.g == null && (drawable = this.q) != null) {
                C(drawable);
            }
            v(u.k(j.ActionBar_displayOptions, 0));
            int n2 = u.n(j.ActionBar_customNavigationLayout, 0);
            if (n2 != 0) {
                x(LayoutInflater.from(this.f455a.getContext()).inflate(n2, this.f455a, false));
                v(this.f456b | 16);
            }
            int m2 = u.m(j.ActionBar_height, 0);
            if (m2 > 0) {
                ViewGroup.LayoutParams layoutParams = this.f455a.getLayoutParams();
                layoutParams.height = m2;
                this.f455a.setLayoutParams(layoutParams);
            }
            int e2 = u.e(j.ActionBar_contentInsetStart, -1);
            int e3 = u.e(j.ActionBar_contentInsetEnd, -1);
            if (e2 >= 0 || e3 >= 0) {
                this.f455a.H(Math.max(e2, 0), Math.max(e3, 0));
            }
            int n3 = u.n(j.ActionBar_titleTextStyle, 0);
            if (n3 != 0) {
                Toolbar toolbar2 = this.f455a;
                toolbar2.K(toolbar2.getContext(), n3);
            }
            int n4 = u.n(j.ActionBar_subtitleTextStyle, 0);
            if (n4 != 0) {
                Toolbar toolbar3 = this.f455a;
                toolbar3.J(toolbar3.getContext(), n4);
            }
            int n5 = u.n(j.ActionBar_popupTheme, 0);
            if (n5 != 0) {
                this.f455a.setPopupTheme(n5);
            }
        } else {
            this.f456b = w();
        }
        u.v();
        y(i2);
        this.k = this.f455a.getNavigationContentDescription();
        this.f455a.setNavigationOnClickListener(new a());
    }

    private void F(CharSequence charSequence) {
        this.i = charSequence;
        if ((this.f456b & 8) != 0) {
            this.f455a.setTitle(charSequence);
        }
    }

    private void G() {
        if ((this.f456b & 4) == 0) {
            return;
        }
        if (TextUtils.isEmpty(this.k)) {
            this.f455a.setNavigationContentDescription(this.p);
        } else {
            this.f455a.setNavigationContentDescription(this.k);
        }
    }

    private void H() {
        Drawable drawable;
        Toolbar toolbar;
        if ((this.f456b & 4) != 0) {
            toolbar = this.f455a;
            drawable = this.g;
            if (drawable == null) {
                drawable = this.q;
            }
        } else {
            toolbar = this.f455a;
            drawable = null;
        }
        toolbar.setNavigationIcon(drawable);
    }

    private void I() {
        Drawable drawable;
        int i2 = this.f456b;
        if ((i2 & 2) == 0) {
            drawable = null;
        } else if ((i2 & 1) == 0 || (drawable = this.f) == null) {
            drawable = this.e;
        }
        this.f455a.setLogo(drawable);
    }

    private int w() {
        if (this.f455a.getNavigationIcon() == null) {
            return 11;
        }
        this.q = this.f455a.getNavigationIcon();
        return 15;
    }

    public void A(int i2) {
        B(i2 == 0 ? null : o().getString(i2));
    }

    public void B(CharSequence charSequence) {
        this.k = charSequence;
        G();
    }

    public void C(Drawable drawable) {
        this.g = drawable;
        H();
    }

    public void D(CharSequence charSequence) {
        this.j = charSequence;
        if ((this.f456b & 8) != 0) {
            this.f455a.setSubtitle(charSequence);
        }
    }

    public void E(CharSequence charSequence) {
        this.h = true;
        F(charSequence);
    }

    public void a(Menu menu, m.a aVar) {
        if (this.n == null) {
            c cVar = new c(this.f455a.getContext());
            this.n = cVar;
            cVar.p(f.action_menu_presenter);
        }
        this.n.h(aVar);
        this.f455a.I((g) menu, this.n);
    }

    public boolean b() {
        return this.f455a.z();
    }

    public boolean c() {
        return this.f455a.A();
    }

    public void collapseActionView() {
        this.f455a.e();
    }

    public boolean d() {
        return this.f455a.w();
    }

    public boolean e() {
        return this.f455a.N();
    }

    public void f() {
        this.m = true;
    }

    public boolean g() {
        return this.f455a.d();
    }

    public CharSequence getTitle() {
        return this.f455a.getTitle();
    }

    public void h() {
        this.f455a.f();
    }

    public int i() {
        return this.f456b;
    }

    public void j(int i2) {
        this.f455a.setVisibility(i2);
    }

    public void k(int i2) {
        z(i2 != 0 ? b.a.k.a.a.d(o(), i2) : null);
    }

    public void l(p0 p0Var) {
        Toolbar toolbar;
        View view = this.f457c;
        if (view != null && view.getParent() == (toolbar = this.f455a)) {
            toolbar.removeView(this.f457c);
        }
        this.f457c = p0Var;
        if (p0Var != null && this.o == 2) {
            this.f455a.addView(p0Var, 0);
            Toolbar.e eVar = (Toolbar.e) this.f457c.getLayoutParams();
            eVar.width = -2;
            eVar.height = -2;
            eVar.f114a = 8388691;
            p0Var.setAllowCollapse(true);
        }
    }

    public ViewGroup m() {
        return this.f455a;
    }

    public void n(boolean z) {
    }

    public Context o() {
        return this.f455a.getContext();
    }

    public int p() {
        return this.o;
    }

    public w q(int i2, long j2) {
        w c2 = s.c(this.f455a);
        c2.a(i2 == 0 ? 1.0f : 0.0f);
        c2.d(j2);
        c2.f(new b(i2));
        return c2;
    }

    public void r() {
        Log.i("ToolbarWidgetWrapper", "Progress display unsupported");
    }

    public boolean s() {
        return this.f455a.v();
    }

    public void setIcon(int i2) {
        setIcon(i2 != 0 ? b.a.k.a.a.d(o(), i2) : null);
    }

    public void setIcon(Drawable drawable) {
        this.e = drawable;
        I();
    }

    public void setWindowCallback(Window.Callback callback) {
        this.l = callback;
    }

    public void setWindowTitle(CharSequence charSequence) {
        if (!this.h) {
            F(charSequence);
        }
    }

    public void t() {
        Log.i("ToolbarWidgetWrapper", "Progress display unsupported");
    }

    public void u(boolean z) {
        this.f455a.setCollapsible(z);
    }

    public void v(int i2) {
        View view;
        CharSequence charSequence;
        Toolbar toolbar;
        int i3 = this.f456b ^ i2;
        this.f456b = i2;
        if (i3 != 0) {
            if ((i3 & 4) != 0) {
                if ((i2 & 4) != 0) {
                    G();
                }
                H();
            }
            if ((i3 & 3) != 0) {
                I();
            }
            if ((i3 & 8) != 0) {
                if ((i2 & 8) != 0) {
                    this.f455a.setTitle(this.i);
                    toolbar = this.f455a;
                    charSequence = this.j;
                } else {
                    charSequence = null;
                    this.f455a.setTitle((CharSequence) null);
                    toolbar = this.f455a;
                }
                toolbar.setSubtitle(charSequence);
            }
            if ((i3 & 16) != 0 && (view = this.f458d) != null) {
                if ((i2 & 16) != 0) {
                    this.f455a.addView(view);
                } else {
                    this.f455a.removeView(view);
                }
            }
        }
    }

    public void x(View view) {
        View view2 = this.f458d;
        if (!(view2 == null || (this.f456b & 16) == 0)) {
            this.f455a.removeView(view2);
        }
        this.f458d = view;
        if (view != null && (this.f456b & 16) != 0) {
            this.f455a.addView(view);
        }
    }

    public void y(int i2) {
        if (i2 != this.p) {
            this.p = i2;
            if (TextUtils.isEmpty(this.f455a.getNavigationContentDescription())) {
                A(this.p);
            }
        }
    }

    public void z(Drawable drawable) {
        this.f = drawable;
        I();
    }
}
